home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / codecs.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  24.1 KB  |  775 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. ''' codecs -- Python Codec Registry, API and helpers.
  5.  
  6.  
  7. Written by Marc-Andre Lemburg (mal@lemburg.com).
  8.  
  9. (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
  10.  
  11. '''
  12. import __builtin__
  13. import sys
  14.  
  15. try:
  16.     from _codecs import *
  17. except ImportError:
  18.     why = None
  19.     raise SystemError, 'Failed to load the builtin codecs: %s' % why
  20.  
  21. __all__ = [
  22.     'register',
  23.     'lookup',
  24.     'open',
  25.     'EncodedFile',
  26.     'BOM',
  27.     'BOM_BE',
  28.     'BOM_LE',
  29.     'BOM32_BE',
  30.     'BOM32_LE',
  31.     'BOM64_BE',
  32.     'BOM64_LE',
  33.     'BOM_UTF8',
  34.     'BOM_UTF16',
  35.     'BOM_UTF16_LE',
  36.     'BOM_UTF16_BE',
  37.     'BOM_UTF32',
  38.     'BOM_UTF32_LE',
  39.     'BOM_UTF32_BE',
  40.     'strict_errors',
  41.     'ignore_errors',
  42.     'replace_errors',
  43.     'xmlcharrefreplace_errors',
  44.     'register_error',
  45.     'lookup_error']
  46. BOM_UTF8 = '\xef\xbb\xbf'
  47. BOM_LE = BOM_UTF16_LE = '\xff\xfe'
  48. BOM_BE = BOM_UTF16_BE = '\xfe\xff'
  49. BOM_UTF32_LE = '\xff\xfe\x00\x00'
  50. BOM_UTF32_BE = '\x00\x00\xfe\xff'
  51. if sys.byteorder == 'little':
  52.     BOM = BOM_UTF16 = BOM_UTF16_LE
  53.     BOM_UTF32 = BOM_UTF32_LE
  54. else:
  55.     BOM = BOM_UTF16 = BOM_UTF16_BE
  56.     BOM_UTF32 = BOM_UTF32_BE
  57. BOM32_LE = BOM_UTF16_LE
  58. BOM32_BE = BOM_UTF16_BE
  59. BOM64_LE = BOM_UTF32_LE
  60. BOM64_BE = BOM_UTF32_BE
  61.  
  62. class Codec:
  63.     """ Defines the interface for stateless encoders/decoders.
  64.  
  65.         The .encode()/.decode() methods may use different error
  66.         handling schemes by providing the errors argument. These
  67.         string values are predefined:
  68.  
  69.          'strict' - raise a ValueError error (or a subclass)
  70.          'ignore' - ignore the character and continue with the next
  71.          'replace' - replace with a suitable replacement character;
  72.                     Python will use the official U+FFFD REPLACEMENT
  73.                     CHARACTER for the builtin Unicode codecs on
  74.                     decoding and '?' on encoding.
  75.          'xmlcharrefreplace' - Replace with the appropriate XML
  76.                                character reference (only for encoding).
  77.          'backslashreplace'  - Replace with backslashed escape sequences
  78.                                (only for encoding).
  79.  
  80.         The set of allowed values can be extended via register_error.
  81.  
  82.     """
  83.     
  84.     def encode(self, input, errors = 'strict'):
  85.         """ Encodes the object input and returns a tuple (output
  86.             object, length consumed).
  87.  
  88.             errors defines the error handling to apply. It defaults to
  89.             'strict' handling.
  90.  
  91.             The method may not store state in the Codec instance. Use
  92.             StreamCodec for codecs which have to keep state in order to
  93.             make encoding/decoding efficient.
  94.  
  95.             The encoder must be able to handle zero length input and
  96.             return an empty object of the output object type in this
  97.             situation.
  98.  
  99.         """
  100.         raise NotImplementedError
  101.  
  102.     
  103.     def decode(self, input, errors = 'strict'):
  104.         """ Decodes the object input and returns a tuple (output
  105.             object, length consumed).
  106.  
  107.             input must be an object which provides the bf_getreadbuf
  108.             buffer slot. Python strings, buffer objects and memory
  109.             mapped files are examples of objects providing this slot.
  110.  
  111.             errors defines the error handling to apply. It defaults to
  112.             'strict' handling.
  113.  
  114.             The method may not store state in the Codec instance. Use
  115.             StreamCodec for codecs which have to keep state in order to
  116.             make encoding/decoding efficient.
  117.  
  118.             The decoder must be able to handle zero length input and
  119.             return an empty object of the output object type in this
  120.             situation.
  121.  
  122.         """
  123.         raise NotImplementedError
  124.  
  125.  
  126.  
  127. class StreamWriter(Codec):
  128.     
  129.     def __init__(self, stream, errors = 'strict'):
  130.         """ Creates a StreamWriter instance.
  131.  
  132.             stream must be a file-like object open for writing
  133.             (binary) data.
  134.  
  135.             The StreamWriter may use different error handling
  136.             schemes by providing the errors keyword argument. These
  137.             parameters are predefined:
  138.  
  139.              'strict' - raise a ValueError (or a subclass)
  140.              'ignore' - ignore the character and continue with the next
  141.              'replace'- replace with a suitable replacement character
  142.              'xmlcharrefreplace' - Replace with the appropriate XML
  143.                                    character reference.
  144.              'backslashreplace'  - Replace with backslashed escape
  145.                                    sequences (only for encoding).
  146.  
  147.             The set of allowed parameter values can be extended via
  148.             register_error.
  149.         """
  150.         self.stream = stream
  151.         self.errors = errors
  152.  
  153.     
  154.     def write(self, object):
  155.         """ Writes the object's contents encoded to self.stream.
  156.         """
  157.         (data, consumed) = self.encode(object, self.errors)
  158.         self.stream.write(data)
  159.  
  160.     
  161.     def writelines(self, list):
  162.         ''' Writes the concatenated list of strings to the stream
  163.             using .write().
  164.         '''
  165.         self.write(''.join(list))
  166.  
  167.     
  168.     def reset(self):
  169.         ''' Flushes and resets the codec buffers used for keeping state.
  170.  
  171.             Calling this method should ensure that the data on the
  172.             output is put into a clean state, that allows appending
  173.             of new fresh data without having to rescan the whole
  174.             stream to recover state.
  175.  
  176.         '''
  177.         pass
  178.  
  179.     
  180.     def __getattr__(self, name, getattr = getattr):
  181.         ''' Inherit all other methods from the underlying stream.
  182.         '''
  183.         return getattr(self.stream, name)
  184.  
  185.  
  186.  
  187. class StreamReader(Codec):
  188.     
  189.     def __init__(self, stream, errors = 'strict'):
  190.         """ Creates a StreamReader instance.
  191.  
  192.             stream must be a file-like object open for reading
  193.             (binary) data.
  194.  
  195.             The StreamReader may use different error handling
  196.             schemes by providing the errors keyword argument. These
  197.             parameters are predefined:
  198.  
  199.              'strict' - raise a ValueError (or a subclass)
  200.              'ignore' - ignore the character and continue with the next
  201.              'replace'- replace with a suitable replacement character;
  202.  
  203.             The set of allowed parameter values can be extended via
  204.             register_error.
  205.         """
  206.         self.stream = stream
  207.         self.errors = errors
  208.         self.bytebuffer = ''
  209.         self.charbuffer = ''
  210.         self.linebuffer = None
  211.  
  212.     
  213.     def decode(self, input, errors = 'strict'):
  214.         raise NotImplementedError
  215.  
  216.     
  217.     def read(self, size = -1, chars = -1, firstline = False):
  218.         ''' Decodes data from the stream self.stream and returns the
  219.             resulting object.
  220.  
  221.             chars indicates the number of characters to read from the
  222.             stream. read() will never return more than chars
  223.             characters, but it might return less, if there are not enough
  224.             characters available.
  225.  
  226.             size indicates the approximate maximum number of bytes to
  227.             read from the stream for decoding purposes. The decoder
  228.             can modify this setting as appropriate. The default value
  229.             -1 indicates to read and decode as much as possible.  size
  230.             is intended to prevent having to decode huge files in one
  231.             step.
  232.  
  233.             If firstline is true, and a UnicodeDecodeError happens
  234.             after the first line terminator in the input only the first line
  235.             will be returned, the rest of the input will be kept until the
  236.             next call to read().
  237.  
  238.             The method should use a greedy read strategy meaning that
  239.             it should read as much data as is allowed within the
  240.             definition of the encoding and the given size, e.g.  if
  241.             optional encoding endings or state markers are available
  242.             on the stream, these should be read too.
  243.         '''
  244.         if self.linebuffer:
  245.             self.charbuffer = ''.join(self.linebuffer)
  246.             self.linebuffer = None
  247.         
  248.         while True:
  249.             if chars < 0:
  250.                 if size < 0:
  251.                     if self.charbuffer:
  252.                         break
  253.                     
  254.                 elif len(self.charbuffer) >= size:
  255.                     break
  256.                 
  257.             elif len(self.charbuffer) >= chars:
  258.                 break
  259.             
  260.             if size < 0:
  261.                 newdata = self.stream.read()
  262.             else:
  263.                 newdata = self.stream.read(size)
  264.             data = self.bytebuffer + newdata
  265.             
  266.             try:
  267.                 (newchars, decodedbytes) = self.decode(data, self.errors)
  268.             except UnicodeDecodeError:
  269.                 exc = None
  270.                 if firstline:
  271.                     (newchars, decodedbytes) = self.decode(data[:exc.start], self.errors)
  272.                     lines = newchars.splitlines(True)
  273.                     if len(lines) <= 1:
  274.                         raise 
  275.                     
  276.                 else:
  277.                     raise 
  278.             except:
  279.                 firstline
  280.  
  281.             self.bytebuffer = data[decodedbytes:]
  282.             self.charbuffer += newchars
  283.             if not newdata:
  284.                 break
  285.                 continue
  286.             self
  287.         if chars < 0:
  288.             result = self.charbuffer
  289.             self.charbuffer = ''
  290.         else:
  291.             result = self.charbuffer[:chars]
  292.             self.charbuffer = self.charbuffer[chars:]
  293.         return result
  294.  
  295.     
  296.     def readline(self, size = None, keepends = True):
  297.         ''' Read one line from the input stream and return the
  298.             decoded data.
  299.  
  300.             size, if given, is passed as size argument to the
  301.             read() method.
  302.  
  303.         '''
  304.         if self.linebuffer:
  305.             line = self.linebuffer[0]
  306.             del self.linebuffer[0]
  307.             if len(self.linebuffer) == 1:
  308.                 self.charbuffer = self.linebuffer[0]
  309.                 self.linebuffer = None
  310.             
  311.             if not keepends:
  312.                 line = line.splitlines(False)[0]
  313.             
  314.             return line
  315.         
  316.         if not size:
  317.             pass
  318.         readsize = 72
  319.         line = ''
  320.         while True:
  321.             data = self.read(readsize, firstline = True)
  322.             if data:
  323.                 if data.endswith('\r'):
  324.                     data += self.read(size = 1, chars = 1)
  325.                 
  326.             
  327.             line += data
  328.             lines = line.splitlines(True)
  329.             if lines:
  330.                 if len(lines) > 1:
  331.                     line = lines[0]
  332.                     del lines[0]
  333.                     if len(lines) > 1:
  334.                         lines[-1] += self.charbuffer
  335.                         self.linebuffer = lines
  336.                         self.charbuffer = None
  337.                     else:
  338.                         self.charbuffer = lines[0] + self.charbuffer
  339.                     if not keepends:
  340.                         line = line.splitlines(False)[0]
  341.                     
  342.                     break
  343.                 
  344.                 line0withend = lines[0]
  345.                 line0withoutend = lines[0].splitlines(False)[0]
  346.                 if line0withend != line0withoutend:
  347.                     self.charbuffer = ''.join(lines[1:]) + self.charbuffer
  348.                     if keepends:
  349.                         line = line0withend
  350.                     else:
  351.                         line = line0withoutend
  352.                     break
  353.                 
  354.             
  355.             if not data or size is not None:
  356.                 if line and not keepends:
  357.                     line = line.splitlines(False)[0]
  358.                 
  359.                 break
  360.             
  361.             if readsize < 8000:
  362.                 readsize *= 2
  363.                 continue
  364.         return line
  365.  
  366.     
  367.     def readlines(self, sizehint = None, keepends = True):
  368.         """ Read all lines available on the input stream
  369.             and return them as list of lines.
  370.  
  371.             Line breaks are implemented using the codec's decoder
  372.             method and are included in the list entries.
  373.  
  374.             sizehint, if given, is ignored since there is no efficient
  375.             way to finding the true end-of-line.
  376.  
  377.         """
  378.         data = self.read()
  379.         return data.splitlines(keepends)
  380.  
  381.     
  382.     def reset(self):
  383.         ''' Resets the codec buffers used for keeping state.
  384.  
  385.             Note that no stream repositioning should take place.
  386.             This method is primarily intended to be able to recover
  387.             from decoding errors.
  388.  
  389.         '''
  390.         self.bytebuffer = ''
  391.         self.charbuffer = u''
  392.         self.linebuffer = None
  393.  
  394.     
  395.     def seek(self, offset, whence = 0):
  396.         """ Set the input stream's current position.
  397.  
  398.             Resets the codec buffers used for keeping state.
  399.         """
  400.         self.reset()
  401.         self.stream.seek(offset, whence)
  402.  
  403.     
  404.     def next(self):
  405.         ''' Return the next decoded line from the input stream.'''
  406.         line = self.readline()
  407.         if line:
  408.             return line
  409.         
  410.         raise StopIteration
  411.  
  412.     
  413.     def __iter__(self):
  414.         return self
  415.  
  416.     
  417.     def __getattr__(self, name, getattr = getattr):
  418.         ''' Inherit all other methods from the underlying stream.
  419.         '''
  420.         return getattr(self.stream, name)
  421.  
  422.  
  423.  
  424. class StreamReaderWriter:
  425.     ''' StreamReaderWriter instances allow wrapping streams which
  426.         work in both read and write modes.
  427.  
  428.         The design is such that one can use the factory functions
  429.         returned by the codec.lookup() function to construct the
  430.         instance.
  431.  
  432.     '''
  433.     encoding = 'unknown'
  434.     
  435.     def __init__(self, stream, Reader, Writer, errors = 'strict'):
  436.         ''' Creates a StreamReaderWriter instance.
  437.  
  438.             stream must be a Stream-like object.
  439.  
  440.             Reader, Writer must be factory functions or classes
  441.             providing the StreamReader, StreamWriter interface resp.
  442.  
  443.             Error handling is done in the same way as defined for the
  444.             StreamWriter/Readers.
  445.  
  446.         '''
  447.         self.stream = stream
  448.         self.reader = Reader(stream, errors)
  449.         self.writer = Writer(stream, errors)
  450.         self.errors = errors
  451.  
  452.     
  453.     def read(self, size = -1):
  454.         return self.reader.read(size)
  455.  
  456.     
  457.     def readline(self, size = None):
  458.         return self.reader.readline(size)
  459.  
  460.     
  461.     def readlines(self, sizehint = None):
  462.         return self.reader.readlines(sizehint)
  463.  
  464.     
  465.     def next(self):
  466.         ''' Return the next decoded line from the input stream.'''
  467.         return self.reader.next()
  468.  
  469.     
  470.     def __iter__(self):
  471.         return self
  472.  
  473.     
  474.     def write(self, data):
  475.         return self.writer.write(data)
  476.  
  477.     
  478.     def writelines(self, list):
  479.         return self.writer.writelines(list)
  480.  
  481.     
  482.     def reset(self):
  483.         self.reader.reset()
  484.         self.writer.reset()
  485.  
  486.     
  487.     def __getattr__(self, name, getattr = getattr):
  488.         ''' Inherit all other methods from the underlying stream.
  489.         '''
  490.         return getattr(self.stream, name)
  491.  
  492.  
  493.  
  494. class StreamRecoder:
  495.     ''' StreamRecoder instances provide a frontend - backend
  496.         view of encoding data.
  497.  
  498.         They use the complete set of APIs returned by the
  499.         codecs.lookup() function to implement their task.
  500.  
  501.         Data written to the stream is first decoded into an
  502.         intermediate format (which is dependent on the given codec
  503.         combination) and then written to the stream using an instance
  504.         of the provided Writer class.
  505.  
  506.         In the other direction, data is read from the stream using a
  507.         Reader instance and then return encoded data to the caller.
  508.  
  509.     '''
  510.     data_encoding = 'unknown'
  511.     file_encoding = 'unknown'
  512.     
  513.     def __init__(self, stream, encode, decode, Reader, Writer, errors = 'strict'):
  514.         ''' Creates a StreamRecoder instance which implements a two-way
  515.             conversion: encode and decode work on the frontend (the
  516.             input to .read() and output of .write()) while
  517.             Reader and Writer work on the backend (reading and
  518.             writing to the stream).
  519.  
  520.             You can use these objects to do transparent direct
  521.             recodings from e.g. latin-1 to utf-8 and back.
  522.  
  523.             stream must be a file-like object.
  524.  
  525.             encode, decode must adhere to the Codec interface, Reader,
  526.             Writer must be factory functions or classes providing the
  527.             StreamReader, StreamWriter interface resp.
  528.  
  529.             encode and decode are needed for the frontend translation,
  530.             Reader and Writer for the backend translation. Unicode is
  531.             used as intermediate encoding.
  532.  
  533.             Error handling is done in the same way as defined for the
  534.             StreamWriter/Readers.
  535.  
  536.         '''
  537.         self.stream = stream
  538.         self.encode = encode
  539.         self.decode = decode
  540.         self.reader = Reader(stream, errors)
  541.         self.writer = Writer(stream, errors)
  542.         self.errors = errors
  543.  
  544.     
  545.     def read(self, size = -1):
  546.         data = self.reader.read(size)
  547.         (data, bytesencoded) = self.encode(data, self.errors)
  548.         return data
  549.  
  550.     
  551.     def readline(self, size = None):
  552.         if size is None:
  553.             data = self.reader.readline()
  554.         else:
  555.             data = self.reader.readline(size)
  556.         (data, bytesencoded) = self.encode(data, self.errors)
  557.         return data
  558.  
  559.     
  560.     def readlines(self, sizehint = None):
  561.         data = self.reader.read()
  562.         (data, bytesencoded) = self.encode(data, self.errors)
  563.         return data.splitlines(1)
  564.  
  565.     
  566.     def next(self):
  567.         ''' Return the next decoded line from the input stream.'''
  568.         data = self.reader.next()
  569.         (data, bytesencoded) = self.encode(data, self.errors)
  570.         return data
  571.  
  572.     
  573.     def __iter__(self):
  574.         return self
  575.  
  576.     
  577.     def write(self, data):
  578.         (data, bytesdecoded) = self.decode(data, self.errors)
  579.         return self.writer.write(data)
  580.  
  581.     
  582.     def writelines(self, list):
  583.         data = ''.join(list)
  584.         (data, bytesdecoded) = self.decode(data, self.errors)
  585.         return self.writer.write(data)
  586.  
  587.     
  588.     def reset(self):
  589.         self.reader.reset()
  590.         self.writer.reset()
  591.  
  592.     
  593.     def __getattr__(self, name, getattr = getattr):
  594.         ''' Inherit all other methods from the underlying stream.
  595.         '''
  596.         return getattr(self.stream, name)
  597.  
  598.  
  599.  
  600. def open(filename, mode = 'rb', encoding = None, errors = 'strict', buffering = 1):
  601.     """ Open an encoded file using the given mode and return
  602.         a wrapped version providing transparent encoding/decoding.
  603.  
  604.         Note: The wrapped version will only accept the object format
  605.         defined by the codecs, i.e. Unicode objects for most builtin
  606.         codecs. Output is also codec dependent and will usually by
  607.         Unicode as well.
  608.  
  609.         Files are always opened in binary mode, even if no binary mode
  610.         was specified. This is done to avoid data loss due to encodings
  611.         using 8-bit values. The default file mode is 'rb' meaning to
  612.         open the file in binary read mode.
  613.  
  614.         encoding specifies the encoding which is to be used for the
  615.         file.
  616.  
  617.         errors may be given to define the error handling. It defaults
  618.         to 'strict' which causes ValueErrors to be raised in case an
  619.         encoding error occurs.
  620.  
  621.         buffering has the same meaning as for the builtin open() API.
  622.         It defaults to line buffered.
  623.  
  624.         The returned wrapped file object provides an extra attribute
  625.         .encoding which allows querying the used encoding. This
  626.         attribute is only available if an encoding was specified as
  627.         parameter.
  628.  
  629.     """
  630.     if encoding is not None and 'b' not in mode:
  631.         mode = mode + 'b'
  632.     
  633.     file = __builtin__.open(filename, mode, buffering)
  634.     if encoding is None:
  635.         return file
  636.     
  637.     (e, d, sr, sw) = lookup(encoding)
  638.     srw = StreamReaderWriter(file, sr, sw, errors)
  639.     srw.encoding = encoding
  640.     return srw
  641.  
  642.  
  643. def EncodedFile(file, data_encoding, file_encoding = None, errors = 'strict'):
  644.     """ Return a wrapped version of file which provides transparent
  645.         encoding translation.
  646.  
  647.         Strings written to the wrapped file are interpreted according
  648.         to the given data_encoding and then written to the original
  649.         file as string using file_encoding. The intermediate encoding
  650.         will usually be Unicode but depends on the specified codecs.
  651.  
  652.         Strings are read from the file using file_encoding and then
  653.         passed back to the caller as string using data_encoding.
  654.  
  655.         If file_encoding is not given, it defaults to data_encoding.
  656.  
  657.         errors may be given to define the error handling. It defaults
  658.         to 'strict' which causes ValueErrors to be raised in case an
  659.         encoding error occurs.
  660.  
  661.         The returned wrapped file object provides two extra attributes
  662.         .data_encoding and .file_encoding which reflect the given
  663.         parameters of the same name. The attributes can be used for
  664.         introspection by Python programs.
  665.  
  666.     """
  667.     if file_encoding is None:
  668.         file_encoding = data_encoding
  669.     
  670.     (encode, decode) = lookup(data_encoding)[:2]
  671.     (Reader, Writer) = lookup(file_encoding)[2:]
  672.     sr = StreamRecoder(file, encode, decode, Reader, Writer, errors)
  673.     sr.data_encoding = data_encoding
  674.     sr.file_encoding = file_encoding
  675.     return sr
  676.  
  677.  
  678. def getencoder(encoding):
  679.     ''' Lookup up the codec for the given encoding and return
  680.         its encoder function.
  681.  
  682.         Raises a LookupError in case the encoding cannot be found.
  683.  
  684.     '''
  685.     return lookup(encoding)[0]
  686.  
  687.  
  688. def getdecoder(encoding):
  689.     ''' Lookup up the codec for the given encoding and return
  690.         its decoder function.
  691.  
  692.         Raises a LookupError in case the encoding cannot be found.
  693.  
  694.     '''
  695.     return lookup(encoding)[1]
  696.  
  697.  
  698. def getreader(encoding):
  699.     ''' Lookup up the codec for the given encoding and return
  700.         its StreamReader class or factory function.
  701.  
  702.         Raises a LookupError in case the encoding cannot be found.
  703.  
  704.     '''
  705.     return lookup(encoding)[2]
  706.  
  707.  
  708. def getwriter(encoding):
  709.     ''' Lookup up the codec for the given encoding and return
  710.         its StreamWriter class or factory function.
  711.  
  712.         Raises a LookupError in case the encoding cannot be found.
  713.  
  714.     '''
  715.     return lookup(encoding)[3]
  716.  
  717.  
  718. def make_identity_dict(rng):
  719.     ''' make_identity_dict(rng) -> dict
  720.  
  721.         Return a dictionary where elements of the rng sequence are
  722.         mapped to themselves.
  723.  
  724.     '''
  725.     res = { }
  726.     for i in rng:
  727.         res[i] = i
  728.     
  729.     return res
  730.  
  731.  
  732. def make_encoding_map(decoding_map):
  733.     ''' Creates an encoding map from a decoding map.
  734.  
  735.         If a target mapping in the decoding map occurs multiple
  736.         times, then that target is mapped to None (undefined mapping),
  737.         causing an exception when encountered by the charmap codec
  738.         during translation.
  739.  
  740.         One example where this happens is cp875.py which decodes
  741.         multiple character to \\u001a.
  742.  
  743.     '''
  744.     m = { }
  745.     for k, v in decoding_map.items():
  746.         if v not in m:
  747.             m[v] = k
  748.             continue
  749.         m[v] = None
  750.     
  751.     return m
  752.  
  753.  
  754. try:
  755.     strict_errors = lookup_error('strict')
  756.     ignore_errors = lookup_error('ignore')
  757.     replace_errors = lookup_error('replace')
  758.     xmlcharrefreplace_errors = lookup_error('xmlcharrefreplace')
  759.     backslashreplace_errors = lookup_error('backslashreplace')
  760. except LookupError:
  761.     strict_errors = None
  762.     ignore_errors = None
  763.     replace_errors = None
  764.     xmlcharrefreplace_errors = None
  765.     backslashreplace_errors = None
  766.  
  767. _false = 0
  768. if _false:
  769.     import encodings
  770.  
  771. if __name__ == '__main__':
  772.     sys.stdout = EncodedFile(sys.stdout, 'latin-1', 'utf-8')
  773.     sys.stdin = EncodedFile(sys.stdin, 'utf-8', 'latin-1')
  774.  
  775.